<template>
	<view class="content">
		<video class="video" src="http://162.14.104.207:8000/static/lookvideo/4c5752e6-6fa2-11ec-b5ea-556b45fb49a9.mp4"
		  autoplay="true"></video>
		<view class="submit-box" @click="upload">
			上传视频
	
		</view>
			<u-popup v-model="show" mode="top" border-radius="14">
				<view>
						<u-circle-progress active-color="#2979ff" :percent="percent">
							<view class="u-progress-content">
								<view class="u-progress-dot"></view>
								<text class='u-progress-info'>查找中</text>
							</view>
						</u-circle-progress>
				</view>
			</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				percent: 0,
				loading: false,
				disabled: false,
				show:false
			}
		},
		methods: {
			upload() {
				let _self = this;
				console.log(_self.severUrl);
				var usertoken = uni.getStorageSync("usertoken");
				var info=uni.getStorageSync("accountInfo");
				console.log(info.openid)
				uni.chooseVideo({
					count: 1,
					sourceType: ['camera', 'album'], //从相册选择
					success: function(res) {
						const tempFilePaths = res.tempFilePath;
						_self.show=true;
						const uploadTask = uni.uploadFile({
							url:'http://www.brainseek.cn:8000/video/submitVideo',
							filePath: res.tempFilePath,
							name: 'file',
							formData: {
								'user': 'test',
								"openid":info.openid
							},
							header: {
								"usertoken": usertoken
							},
							success: function(uploadFileRes) {
								console.log(uploadFileRes.data);
							}
						});

						uploadTask.onProgressUpdate(function(res) {
							_self.percent = res.progress;
							// console.log('上传进度' + res.progress);
							// console.log('已经上传的数据长度' + res.totalBytesSent);
							// console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);
							if(_self.percent==100){
								_self.show=false;
								uni.showToast({
									title:"上传完毕,评估中"
								})
								// uni.navigateBack({
								// 	delta:1
								// })
								uni.reLaunch({
									url:'/pages/tabBar/gait-assess/gait-assess?indexTab=1'
								})
							}
						});
					},
					error: function(e) {
						console.log(e);
					}
				});
			}


		}
	}
</script>

<style>
	@import url("gait-video.css");
</style>
